package com.webank.weideagroup2.service.impl;


import com.webank.weideagroup2.bean.*;
import org.springframework.stereotype.Service;

import com.webank.weideagroup2.chain.Chain;
import com.webank.weideagroup2.chain.ChainBuilder;
import com.webank.weideagroup2.service.RecordService;

import javax.annotation.PostConstruct;

@Service
public class RecordServiceImpl implements RecordService {

    private Chain chain;

    @PostConstruct
    private void init() {
        chain = ChainBuilder.newInstance();
    }


    @Override
    public int uploadPurchaseRecord(PurchaseRecord purchaseRecord) throws Exception {

        chain.uploadRecord(purchaseRecord);

        //上传应给个返回码
        //int resultCode =  chain.uploadRecord(purchaseRecord);
        return ResultCode.SUCCESS;
    }

    @Override
    public int addInsuranceRecord(InsuranceRecord insuranceRecord) throws Exception {

        chain.uploadRecord(insuranceRecord);

        return ResultCode.SUCCESS;
    }

    @Override
    public int addAccidentRecordService(AccidentRecord accidentRecord) throws Exception {

        chain.uploadRecord(accidentRecord);

        return ResultCode.SUCCESS;
    }

    @Override
    public int addInspectionRecordService(InspectionRecord inspectionRecord) throws Exception {

        chain.uploadRecord(inspectionRecord);

        return ResultCode.SUCCESS;
    }

    @Override
    public int addTransactionRecordService(TransactionRecord transactionRecord) throws Exception {

        chain.uploadRecord(transactionRecord);

        return ResultCode.SUCCESS;
    }

}
